﻿namespace Leo.Common.RabbitMQ
{
    /// <summary>
    /// 队列 交换机
    /// </summary>
    public class RabbitExchangeInfo : RabbitObjectBase
    {
        public RabbitExchangeInfo(string name, ExchangeWorkMode exchangeType) : base(name)
        {
            base.AutoDelete = false;
            base.Durable = true;
            this.ExchangeType = exchangeType;
        }

        public RabbitExchangeInfo(string name, ExchangeWorkMode exchangeType, bool durable, bool autoDelete) : this(name, exchangeType)
        {
            base.Durable = durable;
            base.AutoDelete = autoDelete;
        }

        public ExchangeWorkMode ExchangeType { get; set; }

        public RabbitExchangeInfo RedeclareWhenConflict()
        {
            this.redeclared = true;
            return this;
        }

        internal override bool Declare(RabbitConnection connection)
        {
            throw new NotImplementedException();
        }

        internal string GetRetryDestination(string routingKey)
        {
            string text = Utils.CombineRetryExchangeOrQueueName(base.Name);
            string stringValue = Utils.GetDeadOrRetryExchangeType(this.ExchangeType.ToString()).GetStringValue();
            return string.Concat(new string[]
            {
                stringValue,
                "://",
                text,
                "/",
                routingKey
            });
        }

        internal string GetDeadDestination()
        {
            string str = Utils.CombineDeadExchangeOrQueueName(base.Name);
            return Utils.GetDeadOrRetryExchangeType(this.ExchangeType.ToString()).GetStringValue() + "://" + str + "/#";
        }

        public string GetPseudoUrl(string routingKey)
        {
            return string.Concat(new string[]
            {
                this.ExchangeType.ToString().ToLower(),
                "://",
                base.Name,
                "/",
                routingKey
            });
        }
    }
}
